<?php
if($_GET['mode']=="edit"){
   if($_POST['submit_news']!=true) echo '';
   else {
      $select_u = mysql_query('SELECT teacher_to FROM users WHERE username = "'.$_SESSION['username'].'"');
      $row_u = mysql_fetch_assoc($select_u);
	  
      $news_name = addslashes(trim(htmlspecialchars($_POST['news_name'])));
	  $news_descr = addslashes(trim(htmlspecialchars($_POST['news_descr'])));
	  $content= addslashes(trim(htmlspecialchars($_POST['content'])));
	  
	  if(empty($news_name) || empty($news_descr) || empty($content)){
	     echo '<p class="error">Моля, попълнете ВСИЧКИ полета!</p>';
	  } else {
	     $sel_m = mysql_query('SELECT news_name FROM news WHERE news_name = "'.$news_name.'" AND news_id != '.$_GET['id'].'');
		 if(mysql_num_rows($sel_m) != 0){
		    echo '<p class="error">Името на новината е заето!</p>';
		 } else {
		    if(strlen($news_name)<3 || strlen($news_descr)<3 || strlen($content)<3){
			   echo '<p class="error">Кратко име и/или описание и/или статия</p>';
			} else {
			   $update='UPDATE news SET news_name="' . $news_name. '", news_descr="'. $news_descr . '", content="'.$content.'" WHERE news_id='.$_GET['id'].'';
		       $res_update=mysql_query($update);
			   echo '<p class="success">Успешно обновяване!</p>';
			   echo '<meta http-equiv="refresh" content="1;url=editnews.php">';
			} 
		 }
	  }
   }
}
?>